package com.example.cloudpracticeplatform.service.impl;

import com.example.cloudpracticeplatform.entity.Course;
import com.example.cloudpracticeplatform.mapper.CourseMapper;
import com.example.cloudpracticeplatform.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public int addCourse(Course course) {
        return courseMapper.insert(course);
    }

    @Override
    public int updateCourse(Course course) {
        return courseMapper.update(course);
    }

    @Override
    public int deleteCourse(Integer courseId) {
        return courseMapper.delete(courseId);
    }

    @Override
    public Course getCourseById(Integer courseId) {
        return courseMapper.findById(courseId);
    }

    @Override
    public List<Course> getCourses(int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return courseMapper.findAll(offset, pageSize);
    }

    @Override
    public int updateImageId(Integer courseId, String imageId) {
        return courseMapper.updateImageId(courseId, imageId);
    }
}